#! /usr/bin/python

import sys
import getopt
import os
import pwd
import getpass
import Sysaccess
#to change current path
os.chdir(os.path.abspath(os.path.dirname(__file__)))
#import Controller

def help():
    print "-d"
    print "    debug"
    
    print "-v --verbose"
    print "    verbose"
    
    print "-V --version"
    print "    Version"
    
    print "--mL --mountlocation"
    print "    mount les shares de la Location"
    
    print "--mS --mountshare"
    print "    mount un share"
    
    print "-D --D --detect"
    print "    detect and return the location"
       
    print "--mD --mountdetect"
    print "    detect and mount the location"
    exit(0)

#check if started
#proc = os.popen("ps ax | grep miam.py")
#i=proc.read().split('\n')
#if len(i) > 3:
#    print "Miam is already started"
#    exit(0)

#check if root
user_home_path = os.getenv("HOME")
if Sysaccess.check_root() == False:
    if len(sys.argv) == 1:
        os.system('gksu -m Miam\ need\ to\ be\ root\ to\ mount\ share  "python2.5 ./Controller.py --user_path='+user_home_path+'"')
        exit(0)
    print "need to be root !!!"
    exit(0)

#check if the user want a graphical interface
if len(sys.argv) == 1:
        os.system("python2.5 ./Controller.py --user_path="+user_home_path)
        exit(0)


#Check arguments
try:
    optlist, args = getopt.getopt(sys.argv[1:], 'hdvVD' , ['help','debug','verbose','version','mL','mountlocation','mS','mountshare','D','mD','mountdetect'])
except getopt.GetoptError, err:
    print str(err)
    help()
for a in args:
   print a+" arguments invalid"
   help()

for o,a in optlist:
    if o in ('-h',"--help"):
         help()
    elif o in ("-d","--debug"):
        print "Debug"
    elif o in ("-v","--verbose"):
        print "Verbose"
    elif o in ("-V","--version"):
        print "Version"
    elif o in ('--mL','--mountlocation'):
        print "mL"
    elif o in ('--mS','--mountshare'):
        print "mS"
    elif o in ('-D','--D','--detect'):
        print "detect"
    elif o in ('--mD','--mountdetect'):
        print "mD"
        
